<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>v-for</title>
  <script src="../assets/js/vue.js"></script>
</head>
<body>
  <h1>v-for</h1>
  <hr>
  <div id="app">
    <ul>
      <li v-for="(item, index) in sortItems">
        {{ item }}
      </li>
    </ul>
    <hr>
    <ul>
      <li v-for="(student, index) in studentSorts">
        {{ index + 1 }}: {{ student.name }} - {{ student.age }}
      </li>
    </ul>
  </div>
  <script>
    var app = new Vue({
      el: '#app',
      data: {
        items: [53, 23, 76, 14, 5, 36, 28],
        students: [{
          name: 'Cs',
          age: 25
        }, {
          name: 'Panda',
          age: 28
        }, {
          name: 'PanPan',
          age: 2
        }, {
          name: 'King',
          age: 14
        }]
      },
      computed: {
        sortItems: function() {
          return this.items.sort(sortMethod)
        },
        studentSorts: function() { 
          return this.students.sort(sortFun)
        }
      }
    })
    // 进行数组的排序，自定义方法
    function sortMethod(a, b) {
      return a - b;
    }
    function sortFun(a, b) {
        return a.age - b.age;
    }
  </script>
</body>
</html>